[LargestContentfulPaint] Add poster video test and checkImage() helper This CL adds a test for poster image of video. It also adds a helper script with a checkImage() helper which is used in the tests where LCP entry with image is expected. The last parameter is an options array which is used to specify different expected behaviors. Bug: 994414 Change-Id: If0d085aa4569d2ce2d116734819c18028700ad8d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1764416 Reviewed-by: Steve Kobes <skobes@chromium.org> Commit-Queue: Nicolás Peña Moreno <npm@chromium.org> Cr-Commit-Position: refs/heads/master@{#691736} diff --git a/largest-contentful-paint/observe-image.html b/largest-contentful-paint/observe-image.html index a9556eb..5856795 100644 --- a/largest-contentful-paint/observe-image.html +++ b/largest-contentful-paint/observe-image.html
@@ -4,35 +4,21 @@ <body> <script src="/resources/testharness.js"></script> <script src="/resources/testharnessreport.js"></script> +<script src="resources/largest-contentful-paint-helpers.js"></script> <script> async_test(function (t) { if (!window.LargestContentfulPaint) { assert_unreached("LargestContentfulPaint is not implemented"); } - const beforeRender = performance.now(); + const beforeLoad = performance.now(); const observer = new PerformanceObserver( t.step_func_done(function(entryList) { assert_equals(entryList.getEntries().length, 1); const entry = entryList.getEntries()[0]; - assert_equals(entry.entryType, 'largest-contentful-paint'); - assert_greater_than_equal(entry.renderTime, beforeRender, - 'The rendering timestamp should occur after script starts running.'); - assert_greater_than_equal(performance.now(), entry.renderTime, - 'The rendering timestamp should occur before the entry is dispatched to the observer.'); - assert_equals(entry.startTime, entry.renderTime, 'startTime should equal renderTime'); - assert_equals(entry.duration, 0); - // blue.png is 133 x 106. - assert_equals(entry.size, 14098); - assert_equals(entry.id, 'image_id'); - // 25 is the length of "largest-contentful-paint/". - const index = window.location.href.lastIndexOf('/') - 25; - const pathname = window.location.href.substring(0, index) + '/images/blue.png'; - assert_equals(entry.url, pathname); - assert_greater_than(entry.loadTime, beforeRender, - 'The load timestamp should occur after script starts running.'); - assert_less_than(entry.loadTime, entry.renderTime, - 'The load timestamp should occur before the render timestamp.') - assert_equals(entry.element, document.getElementById('image_id')); + const url = window.location.origin + '/images/blue.png'; + // blue.png is 133 by 106. + const size = 133 * 106; + checkImage(entry, url, 'image_id', size, beforeLoad); }) ); observer.observe({type: 'largest-contentful-paint', buffered: true});